package com.parsifal.http;

import java.util.Map;

/**
 * Created by se1 on 16-11-16.
 */
public class HttpUtil {

    private HttpURLConnectionUtil mHttpURLConnectionUtil = null;

    private HttpUtil() {
        mHttpURLConnectionUtil = new HttpURLConnectionUtil();
    }

    private static class SingletonHolder {
        private final static HttpUtil INSTANCE = new HttpUtil();
    }

    public static HttpUtil getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public void get(final String host, final Map<String, String> params, final HttpCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mHttpURLConnectionUtil.setCallback(callback);
                mHttpURLConnectionUtil.get(host, params);
            }
        }).start();
    }

    public void post(final String host, final Map<String, String> params, final HttpCallback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mHttpURLConnectionUtil.setCallback(callback);
                mHttpURLConnectionUtil.post(host, params);
            }
        }).start();
    }
}
